<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>受保护页面APP2</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background-color: #f8f9fa;
            margin: 0;
            padding: 0;
        }
        .header {
            background-color: #343a40;
            color: white;
            padding: 1rem 2rem;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .container {
            max-width: 800px;
            margin: 2rem auto;
            padding: 0 1rem;
        }
        .card {
            background: white;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            padding: 2rem;
            margin-bottom: 2rem;
        }
        h1 {
            color: #343a40;
            margin-top: 0;
        }
        .btn {
            display: inline-block;
            padding: 0.75rem 1.5rem;
            background-color: #007bff;
            color: white;
            text-decoration: none;
            border-radius: 4px;
            font-weight: 500;
            transition: background-color 0.3s;
        }
        .btn:hover {
            background-color: #0069d9;
        }
        .btn-logout {
            background-color: #dc3545;
        }
        .btn-logout:hover {
            background-color: #c82333;
        }
        .user-info {
            background-color: #e9ecef;
            padding: 1rem;
            border-radius: 4px;
            margin-top: 1.5rem;
        }
        .app-name {
            font-size: 1.25rem;
            font-weight: 600;
        }
        .token-info {
            background-color: #f8f9fa;
            border-left: 4px solid #007bff;
            padding: 1rem;
            margin: 1.5rem 0;
            font-family: monospace;
            font-size: 0.9rem;
            white-space: pre-wrap;
            word-break: break-all;
        }
    </style>
</head>
<body>
    <div class="header">
        <div class="app-name" th:text="${@environment.getProperty('spring.application.name')}">Client App</div>
        <div>
            <a th:href="@{/}" class="btn" style="margin-right: 0.5rem;">返回首页</a>
            <a href="/logout" class="btn btn-logout">退出登录</a>
        </div>
    </div>

    <div class="container">
        <div class="card">
            <h1>受保护资源</h1>
            <p>您已成功通过单点登录认证访问此页面。</p>

            <div class="user-info">
                <p><strong>当前应用:</strong> <span th:text="${@environment.getProperty('spring.application.name')}">应用名称</span></p>
                <p><strong>登录用户:</strong> <span th:text="${userName}">用户名</span></p>
                <p><strong>用户Token:</strong> <span th:text="${idToken}">Token</span></p>
                <p><strong>用户角色:</strong>
                    <span th:each="auth : ${#authorities}">
                        <span th:text="${auth.authority}">ROLE_USER</span>
                    </span>
                </p>
            </div>

            <div th:if="${#userAttributes}">
                <h3>用户属性</h3>
                <div class="token-info">
                    <div th:each="attr : ${#userAttributes}">
                        <strong th:text="${attr.key}">属性名</strong>:
                        <span th:text="${attr.value}">属性值</span>
                    </div>
                </div>
            </div>

        </div>

        <div class="card">
            <h2>访问其他应用</h2>
            <p>您已登录单点登录系统，可以直接访问其他客户端应用:</p>
            <div style="display: flex; gap: 1rem; margin-top: 1rem;">
                <a href="http://localhost:8081/secured" class="btn">客户端应用 1</a>
                <a href="http://localhost:8082/secured" class="btn">客户端应用 2</a>
            </div>
        </div>
    </div>
</body>
</html>
